package com.cn.ycy;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
import org.springframework.web.filter.CorsFilter;

@SpringBootApplication(scanBasePackages = {"com.cn"})
@MapperScan("com.cn.ycy.dal.mapper")
@EnableScheduling
public class QuartzSpringbootApplication {

  public static void main(String[] args) {
    SpringApplication.run(QuartzSpringbootApplication.class, args);
  }

  private CorsConfiguration addCorsConfig() {
    CorsConfiguration corsConfiguration = new CorsConfiguration();
    //请求常用的三种配置，*代表允许所有，当时你也可以自定义属性（比如header只能带什么，只能是post方式等等）
    corsConfiguration.addAllowedOrigin("*");
    corsConfiguration.addAllowedHeader("*");
    corsConfiguration.addAllowedMethod("*");
    return corsConfiguration;
  }

  @Bean
  public CorsFilter corsFilter() {
    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", addCorsConfig());
    return new CorsFilter(source);
  }

}
